package com.jzit168.library_retrofit.interceptors

import android.util.Log
import okhttp3.Interceptor
import okhttp3.logging.HttpLoggingInterceptor

/**
 *@Desc: 打印网络请求信息
 *@Author: Android Developer
 *@Date: 2020/10/15
 *
 **/
object LoggingInterceptor {

    private const val TAG = "LoggingInterceptor"

    fun show(isDebug: Boolean): Interceptor = HttpLoggingInterceptor().also {
        HttpLoggingInterceptor.Logger { string ->
            try {
                Log.d(TAG, "show: $string")
            } catch (e: Exception) {
                Log.e(TAG, "show: $e")
            }
        }
        it.level =
            if (isDebug) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
    }
}